{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">添加信息</h3>
    {if condition="($id == 0)"}
    <table class="layui-table  layui-table-form">
        <tr>
            <td colspan="6"><strong>公司信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">公司名称</td>
            <td>
                <input type="text" name="company_name" autocomplete="off" placeholder="请选择公司"
                       class="layui-input license-picker">
                <input type="hidden" name="company_id">
            </td>
            <td class="layui-td-gray">业务类型</td>
            <td>
                <select name="company_type" lay-reqText="公司类型">
                    <option value="">请选择业务类型</option>
                    <option value="1">公司变更</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>经办信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">经办时间</td>
            <td>
                <input type="text" name="handle_time" id="handle_time" autocomplete="off"
                       lay-reqText="经办时间" placeholder="经办时间" class="layui-input">
            </td>
            <td class="layui-td-gray-2">经办进度</td>
            <td>
                <input type="text" name="handle_progress" autocomplete="off"
                       lay-reqText="经办进度" placeholder="经办进度" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">经办对接人</td>
            <td>
                <input type="text" name="handle_dock_person" autocomplete="off" placeholder="经办对接人"
                       lay-reqText="经办对接人" class="layui-input">
            </td>
        </tr>
        <tr id="flow_tr">
            <td class="layui-td-gray">经办人</td>
            <td>
                <input type="text" name="handle_person" autocomplete="off" placeholder="经办人"
                       lay-reqText="经办人" class="layui-input picker-one" readonly><input type="hidden"
                                                                                        name="handle_person_id"
                                                                                        readonly>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">提成金额</td>
            <td>
                <input type="number" name="deduct" autocomplete="off" placeholder="提成金额"
                       class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6">
                <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea"></textarea>
            </td>
        </tr>
    </table>
    {else/}
    <table class="layui-table layui-table-form">
        <tr>
            <td colspan="6"><strong>公司信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">公司名称</td>
            <td>
                <input type="text" name="company_name" value="{$detail.company_name}" autocomplete="off"
                       placeholder="请选择公司"
                       class="layui-input license-picker">
                <input type="hidden" name="company_id" value="{$detail.company_id}">
            </td>
            <td class="layui-td-gray">业务类型</td>
            <td>
                <select name="company_type" lay-reqText="公司类型">
                    <option value=""
                    <?php if($detail['company_type'] == '') echo 'selected' ?>>请选择业务类型</option>
                    <option value="1"
                    <?php if($detail['company_type'] == '1') echo 'selected' ?>>公司变更</option>
                    <option value="2"
                    <?php if($detail['company_type'] == '2') echo 'selected' ?>>报税</option>
                    <option value="3"
                    <?php if($detail['company_type'] == '3') echo 'selected' ?>>注册公司</option>
                    <option value="4"
                    <?php if($detail['company_type'] == '4') echo 'selected' ?>>其他</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="6"><strong>经办信息</strong></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">经办时间</td>
            <td>
                <input type="text" name="handle_time"  id="handle_time"  value="{$detail.handle_time}" autocomplete="off"
                       lay-reqText="经办时间" placeholder="经办时间" class="layui-input">
            </td>
            <td class="layui-td-gray-2">经办进度</td>
            <td>
                <input type="text" name="handle_progress" value="{$detail.handle_progress}" autocomplete="off"
                       lay-reqText="经办进度" placeholder="经办进度" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">经办对接人</td>
            <td>
                <input type="text" name="handle_dock_person" value="{$detail.handle_dock_person}" autocomplete="off"
                       placeholder="经办对接人"
                       lay-reqText="经办对接人" class="layui-input">
            </td>
        </tr>
        <tr id="flow_tr">
            <td class="layui-td-gray">经办人</td>
            <td>
                <input type="text" name="handle_person" value="{$detail.handle_person}" autocomplete="off"
                       placeholder="经办人"
                       lay-reqText="经办人" class="layui-input picker-one" readonly><input type="hidden"
                                                                                        name="handle_person_id"
                                                                                        value="{$detail.handle_person_id}"
                                                                                        readonly>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">提成金额</td>
            <td>
                <input type="number" name="deduct" value="{$detail.deduct}" autocomplete="off" placeholder="提成金额"
                       class="layui-input">
            </td>
        </tr>
        <tr>
            <td colspan="6">
                <textarea name="remark" placeholder="请输入备注信息" class="layui-textarea">{$detail.remark}</textarea>
            </td>
        </tr>
    </table>
    {/if}

    <div class="py-3">
        <input name="id" id="id" type="hidden" value="{$id}">
        <input name="busine_type" type="hidden" value="0">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool', 'employeepicker', 'oaTool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool, table = layui.table, laydate = layui.laydate, oaTool = layui.oaTool,
            employeepicker = layui.employeepicker;

        laydate.render({
            elem: '#handle_time',
            showBottom: false
        });


        //相关附件上传
        oaTool.addFile();
        //radio选择
        form.on('radio(tax)', function (data) {
            if (data.value == 0) {
                $('[name="tax"]').val('0').hide();
            } else {
                $('[name="tax"]').val('').show();
            }
        });

        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/finance/intransact/add", data.field, callback);
            return false;
        });


        form.on('select(flowtype)', function (data) {
            var check_type = data.elem[data.elem.selectedIndex].title;
            var formHtml = '<td class="layui-td-gray">经办人<font>*</font></td>\
		<td colspan="5">\
			<input type="text" name="handle_person" value="" autocomplete="off" placeholder="请选择经办人" lay-verify="required" lay-reqText="请选择经办人" class="layui-input picker-one"><input type="hidden" name="handle_person_id" value="">\
		</td>';
            if (check_type == 2) {
                $('#flow_tr').html(formHtml);
                form.render();
            }
            if (data.value == '') {
                $('#flow_tr').html(formHtml);
                $('[name="copy_names"]').val('');
                $('[name="copy_uids"]').val('');
                form.render();
                return false;
            }
            $.ajax({
                url: "/api/index/get_flow_users",
                type: 'get',
                data: {id: data.value},
                success: function (e) {
                    if (e.code == 0) {
                        var flowLi = '';
                        var flow_data = e.data.flow_data;
                        if (e.data.copy_uids && e.data.copy_uids != '') {
                            $('[name="copy_names"]').val(e.data.copy_unames);
                            $('[name="copy_uids"]').val(e.data.copy_uids.split(','));
                        }
                        if (check_type == 1 || check_type == 3) {
                            for (var a = 0; a < flow_data.length; a++) {
                                var userList = '', sign_type = '';
                                if (check_type == 1) {
                                    if (flow_data[a].flow_type == 1) {
                                        userList += '<li style="padding:3px 0">当前部门负责人</li>';
                                    }
                                    else if (flow_data[a].flow_type == 2) {
                                        userList += '<li style="padding:3px 0">上级部门负责人</li>';
                                    }
                                    else {
                                        if (flow_data[a].flow_type == 3) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">或签</span>';
                                        }
                                        if (flow_data[a].flow_type == 4) {
                                            sign_type = ' <span class="layui-badge layui-bg-blue">会签</span>';
                                        }
                                        for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                            userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                        }
                                    }
                                }
                                else if (check_type == 3) {
                                    sign_type = ' <span class="layui-badge layui-bg-blue">' + flow_data[a].flow_name + '</span>'
                                    for (var b = 0; b < flow_data[a].user_id_info.length; b++) {
                                        userList += '<li style="padding:3px 0"><img src="' + flow_data[a].user_id_info[b].thumb + '" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />' + flow_data[a].user_id_info[b].name + '</li>';
                                    }
                                }
                                flowLi += '<li class="layui-timeline-item">\
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
								<div class="layui-timeline-content">\
								  <p class="layui-timeline-title"><strong>第' + (a + 1) + '级审批</strong>' + sign_type + '</p>\
								  <ul>' + userList + '</ul>\
								</div>\
							</li>';
                            }
                            formHtml = '<td class="layui-td-gray">审批流程</td>\
									<td colspan="7">\
										<ul id="flowList" class="layui-timeline">' + flowLi + '</ul>\
									</td>';
                            $('#flow_tr').html(formHtml);
                        }
                    }
                }
            })
        });


        //选择关联的公司
        $('.license-picker').on('click', function () {
            let that = $(this);
            let callback = function (data) {
                $('[name="company_name"]').val(data.company_name);
                $('[name="company_id"]').val(data.id);


            }
            oaTool.licensePicker(callback);
        });
    }
</script>
{/block}
<!-- /脚本 -->